var passportJwt = require('passport-jwt');
var JwtStrategy = passportJwt.Strategy;
var ExtractJwt = passportJwt.ExtractJwt;
var models=require('../models/models');


module.exports = (passport) => {
  var opts = {
        secretOrKey: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAupYE6SccqNg+/goE/hBc47Tbn06XmxLs2g/rAJOHMwhCi/tNbS4AtrkRMS7is0tSxxnU7iXqufAvmbNeUPOawbGQlPzSslMGh5I6Rvj1BiC0CRv3+9u+7n+Ig4Bi85j3f15k6VlHt+tzHVTqOmETLFdRvAwSSzlAsL28oL6Qy1sv/ivrJFlNRRXOlb5vEmmmDJhA7O59MLMbgA+YSn1P1+2lNhaQAkoQH+KA5tlmmQcVZXra2wsUc+0EgIXnOTMBgAXvAz0RUEzsR0Jsl3ryEhKugaKgpzaxnIy8RysPSxNh25A9vMSAd4olZZhrt9Jo/MpLD8enthRnsDCVl2sRlwIDAQAB',
        jwtFromRequest: ExtractJwt.fromAuthHeader()
  }
  
  var verify = (jwt_payload, done) => {
    models.getModel('mysqlmodel').getAdminByPassword(jwt_payload.username,jwt_payload.password)
          .then(result=>result[0]===undefined?done(null,false):done(null,result[0]))
          .catch(err=>done(err,false))
  }
  passport.use(new JwtStrategy(opts, verify))
}





















